//
//  ImgTextControl.m
//  WatermarkCamera
//
//  Created by 赵新 on 5/7/2024.
//

#import "ImgTextControl.h"
#import <Masonry.h>

@implementation ImgTextControl
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self config];
        [self layoutImgText];
    }
    return self;
}

- (instancetype)initWithTitle:(NSString *)title image:(UIImage *)image {
    self = [self initWithFrame:CGRectZero];
    if (self) {
        self.label.text = title;
        self.imageView.image = image;
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [self initWithFrame:CGRectZero];
    if (self) {
    }
    return self;
}

- (UILabel *)label {
    if (!_label) {
        _label = [[UILabel alloc] init];
        _label.textAlignment = NSTextAlignmentCenter;
        _label.textColor = UIColor.whiteColor;
        [self addSubview:_label];
    }
    return _label;
}

- (UIImageView *)imageView {
    if (!_imageView) {
        _imageView = [[UIImageView alloc] init];
        _imageView.contentMode = UIViewContentModeScaleAspectFit;
        [self addSubview:_imageView];
    }
    return _imageView;
}

- (void)setTitle:(NSString *)title {
    self.label.text = title;
}

- (NSString *)title {
    return self.label.text;
}

- (void)setTextColor:(UIColor *)textColor {
    self.label.textColor = textColor;
}

- (UIColor *)textColor {
    return self.label.textColor;
}

- (void)setFont:(UIFont *)font {
    self.label.font = font;
}

- (UIFont *)font {
    return self.label.font;
}

- (void)setTextAlignment:(NSTextAlignment)textAlignment {
    self.label.textAlignment = textAlignment;
}

- (NSTextAlignment)textAlignment {
    return self.label.textAlignment;
}

- (void)setImgTextSpacing:(CGFloat)imgTextSpacing {
    _imgTextSpacing = imgTextSpacing;
    [self layoutImgText];
}

- (void)setContentEdge:(UIEdgeInsets)contentEdge {
    _contentEdge = contentEdge;
    [self layoutImgText];
}

- (void)setImgSize:(CGFloat)imgSize {
    _imgSize = imgSize;
    [self layoutImgText];
}

- (void)setTintColor:(UIColor *)color {
    self.label.textColor = color;
    self.imageView.image = [self.imageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
    [super setTintColor: color];
}

- (void)setImageTintColor:(UIColor *)color {
    self.imageView.image = [self.imageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
    [super setTintColor: color];
}

- (void)layoutImgText {
    // 子类进行约束布局
}

- (void)config {
    // 配置基础
}

@end
